<script>
//导入router  路由器
import { useRouter } from "vue-router";
import { ref, reactive, toRefs, onMounted } from "vue";
import { setSessionStorage, getSessionStorage } from "../common.js";
import axios from "axios";
import Footer from '@/components/Footer.vue';
export default {

    setup() {
        //实例化router对象
        const router = useRouter();

        //定义需要绑定的数据
        const state = reactive({
            user: getSessionStorage('user'),
            orderData:[], //定义要遍历的数组  数据来自服务端
        });

        getData()

        console.log(state.user.userId)

        function getData(){
            axios.post('api/orders/person',{
                userId:state.user.userId
            }).then((response)=>{
                // console.log(response.data)
                state.orderData=response.data
            })
        }



        function toappointmentcancel(orderId) {
            console.log(orderId)
            axios.post('api/orders/cancel',{
                    orderId:orderId
            }).then((response)=>{
                if(response.data.status==200){
                    // console.log(response.data)
                    router.push('/appointmentcancel')
                }
            }).then((error)=>{
                console.log(error)
            })
        }
        

        return {
            ...toRefs(state),
            toappointmentcancel,
           
        }
    },
    components: {
        Footer
    }

};

</script>



<template>
    <!-- 总容器 -->
    <div class="wrapper">
        <header>
            <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
            <p>我的预约</p>
            <div></div>
        </header>
        <div class="top-ban"></div>

        <ul>
            <li v-for="orderdata in orderData":key="orderdata.index" v-show="orderdata.state == 2 || orderdata.state == 3">
                <div class="left">
                    <p>{{orderdata.orderDate}}</p>
                    <p>{{orderdata.setmealName}}</p>
                </div>
                <div class="right" @click='toappointmentcancel(orderdata.orderId)'  v-show="orderdata.state ==2">
                    取消预约
                </div>
                <div class="right" v-show="orderdata.state ==3">
                    已完成
                </div>
            </li>
        </ul>

        <div class="bottom-ban"></div>
        <Footer></Footer>
    </div>
</template>



<style scoped>
/*********************** 总容器 ***********************/
.wrapper {
    width: 100%;
    height: 100%;
    background-color: #F9F9F9;
}

/*********************** header ***********************/
header {
    width: 100%;
    height: 15.7vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    top: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-sizing: border-box;
    padding: 0 3.6vw;
}

header .fa {
    font-size: 8vw;
}

/*********************** footer ***********************/
footer {
    width: 100%;
    height: 14.2vw;
    box-sizing: border-box;
    border-top: solid 1px #E9E9E9;
    background-color: #FFF;

    position: fixed;
    left: 0;
    bottom: 0;
}

footer ul {
    width: 100%;
    height: 14.2vw;
    display: flex;
    align-items: center;
    justify-content: space-around;
}

footer ul li {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font-size: 3vw;
    color: #999;

    user-select: none;
    cursor: pointer;
}

footer ul li .fa {
    font-size: 5vw;
}

/*********************** common样式 ***********************/
.top-ban {
    width: 100%;
    height: 15.7vw;
}

.bottom-ban {
    width: 100%;
    height: 14.2vw;
}

/*********************** ul ***********************/
ul {
    width: 86vw;
    margin: 0 auto;
}

ul li {
    width: 100%;
    height: 14vw;
    border-bottom: solid 1px #EEE;

    display: flex;
    justify-content: space-between;
    align-items: center;
}

ul li .left {
    user-select: none;
    cursor: pointer;
}

ul li .left p:first-child {
    color: #555;
    font-size: 3.3vw;
}

ul li .left p:last-child {
    color: #333;
    font-size: 4.2vw;
    font-weight: 600;
}

ul li .right {
    font-size: 4vw;
    color: #E6A23C;
}
</style>